package io.renren.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;

import cn.hutool.core.util.StrUtil;
import io.renren.common.utils.ConvertUtils;
import io.renren.core.dao.LearnUserScoreDao;
import io.renren.core.dto.LearnUserScoreDTO;
import io.renren.core.entity.LearnUserScoreEntity;
import io.renren.core.service.LearnUserScoreService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户分数数据
 *
 * @author Ark 6980gong@gmail.com
 * @since 1.0.0 2024-05-27
 */
@Service
public class LearnUserScoreServiceImpl extends CrudServiceImpl<LearnUserScoreDao, LearnUserScoreEntity, LearnUserScoreDTO> implements LearnUserScoreService {

    @Override
    public QueryWrapper<LearnUserScoreEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<LearnUserScoreEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public LearnUserScoreDTO getByUserId(Long userId) {
        return  ConvertUtils.sourceToTarget(baseDao.selectOne(new QueryWrapper<LearnUserScoreEntity>().eq("user_id", userId)), LearnUserScoreDTO.class);
    }
}